import React from 'react';
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx';
import { WeaAuth, WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

@inject('coworkStoreMap')
@observer
export default class NewAuth extends React.Component {
  componentDidMount() {
    const coworkNewStore = this.props.coworkStoreMap.getMapStore(
      this.props.storeMapKey,
    );
    coworkNewStore.getWeaAuthConditions();
  }

  onOk = (datas) => {
    const coworkNewStore = this.props.coworkStoreMap.getMapStore(
      this.props.storeMapKey,
    );
    const { editId, selectValue } = toJS(coworkNewStore.newCoworkStatus);
    coworkNewStore.saveorupdateCoworkShare({
      id: editId,
      typeId: selectValue,
      ...datas,
    });
  };

  onCancel = () => {
    const coworkNewStore = this.props.coworkStoreMap.getMapStore(
      this.props.storeMapKey,
    );
    coworkNewStore.setCreateState({ showAuth: false });
  };
  render() {
    const coworkNewStore = this.props.coworkStoreMap.getMapStore(
      this.props.storeMapKey,
    );
    const { showAuth, authCondition } = toJS(coworkNewStore.newCoworkStatus);
    return (
      <WeaAuth
        ecId={`${(this && this.props && this.props.ecId) || ''}_WeaAuth@yxqx0o`}
        icon="icon-coms-meeting"
        iconBgcolor="#F14A2D"
        title={getLabel(385978, '添加参与者范围')}
        visible={showAuth}
        conditions={authCondition}
        onOk={this.onOk}
        onCancel={this.onCancel}
      />
    );
  }
}
